<div id="page-content">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title" style="text-align:center;">
                    #@installPJaxGoBackBtn()
                    #(o?'编辑':'添加')
                </h3>
            </div>
            <form id="editForm" class="panel-body form-horizontal form-padding">
                <input type="hidden" id="id" name="#(formModelName).id" class="form-control" value="#(o?o.id:'')">
                <div class="form-group">
                    <label class="col-md-3 control-label">问卷标题</label>
                    <div class="col-md-5">
                        <input type="text" name="#(formModelName).paperTitle" class="form-control"
                               value="#(o?o.paperTitle:'')" #if(view=='detail') readonly #end>
                        <small class="help-block">请输入问卷标题</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">问卷摘要</label>
                    <div class="col-md-5">
                        <textarea type="text" rows="5" name="#(formModelName).paperSummary" class="form-control" #if(view=='detail') readonly #end>#(o?o.paperSummary:'')</textarea>
                        <small class="help-block">请输入问卷标题</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">指标项</label>
                    <div class="col-md-5">
                        <div class="input-group mar-btm">
                            <input type="text" id="pName" value="#(pName)" readonly class="form-control">
                            <input type="hidden" id ="pId" name="pId"  value="#(pId)">
                            <input type="hidden" id="pCode" name="pCode" value="#(pCode)">
                            <span class="input-group-btn">
                                <button class="btn btn-mint" type="button" onclick="selectManyItem()">选择</button>
                            </span>
                        </div>
                        <small class="help-block">请选择</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">发布日期</label>
                    <div class="input-group date col-md-5">
                        <input type="text" autocomplete="off" name="#(formModelName).paperStartDate" class="form-control form_datetime"
                               value="#(o?o.paperStartDate:'')" #if(view=='detail') readonly #end>
                        <small class="help-block">请选择发布日期</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">结束日期</label>
                    <div class="input-group date col-md-5">
                        <input type="text" autocomplete="off" name="#(formModelName).paperEndDate" class="form-control form_datetime"
                               value="#(o?o.paperEndDate:'')" #if(view=='detail') readonly #end>
                        <small class="help-block">请选择结束日期</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">问卷分类</label>
                    <div class="col-md-5">
                        <input type="text" name="#(formModelName).paperType" class="form-control"
                               value="#(o?o.paperType:'')" #if(view=='detail') readonly #end>
                        <small class="help-block">请填写问卷分类</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">问卷目标人数</label>
                    <div class="col-md-5">
                        <input type="text" name="#(formModelName).paperPeople" class="form-control"
                               value="#(o?o.paperPeople:'')" #if(view=='detail') readonly #end>
                        <small class="help-block">请输入问卷目标人数</small>
                    </div>
                </div>
                <div class="panel-footer">
                    <div class="row">
                        <div class="col-sm-8 col-sm-offset-3">
                            <button class="btn btn-warning" type="reset">重置</button>
                            <button class="btn btn-mint" type="button" onclick="save()">保存</button>

                        </div>
                    </div>
                </div>
                <input type="hidden" id="paperStatus" name="#(formModelName).paperStatus" value="#(o?o.paperStatus:'')">
            </form>
        </div>
    </div>
</div>
<script>
    //选择一个
    function selectManyItem(){
        pointLion.selectManyItem(function(data){
            var ids = [],names = [],codes = [];
            for(var i=0;i<data.length;i++){
                if(data[i].id!="#root"){
                    ids.push(data[i].id)
                    names.push(data[i].name)
                    codes.push(data[i].icon)
                }
            }
            $("#pId").val(ids);
            $("#pName").val(names);
            $("#pCode").val(codes);
        });
    }

    function save(status) {
//        if(status==1){
//            $("#paperStatus").val(1);
//        }
        var data = common_ajax.ajaxFunc("/admin/paper/save", $('#editForm').serialize(), "json", null);
        if (data.success) {
            pointLion.alertMsg("保存成功!", "success", "small", function () {
                doPjax(ctx + '/admin/paper/getListPage');
            }, data);
        } else {
            pointLion.alertMsg(data.message, "danger", "small", function () {
                $(".btn").removeAttr("disabled");
            }, data);
        }
    }

    $(document).ready(function () {
        $('.form_datetime').datepicker({
            format: 'yyyy-mm-dd',
            weekStart: 1,
            autoclose: 1,
            language:  'zh-CN',
            todayHighlight: 1,
            forceParse: 0
        }).on('changeDate',function(){
        });
        $('#editForm').bootstrapValidator({
            fields: {}
        }).on("success.form.bv", function (e) {
            save();
            return false;
        });
    });
</script>